package com.zagj.videocomparess;

import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.zagj.videocomparess.utils.AudioPlayer;

import java.io.File;

public class AudioActivity extends AppCompatActivity implements View.OnClickListener {

    private String audio_path;
    private AudioPlayer audioPlayer;
    boolean isplaying;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_audio);
        audio_path = getIntent().getStringExtra("audio_path");
        Button viewById = (Button) findViewById(R.id.audio_button1);
        viewById.setOnClickListener(this);
        Button audio_button2 = (Button) findViewById(R.id.audio_button2);
        audio_button2.setOnClickListener(this);
        audioPlayer = new AudioPlayer();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.audio_button1:
          String music_path= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath()+ File.separator+"mydream1.pcm";

                audioPlayer.playMusic(audio_path);
                break;
            case R.id.audio_button2:
                if (!isplaying){
                    audioPlayer.openes(audio_path);
                    isplaying=true;
                }else {
                    audioPlayer.stop();
                    isplaying=false;
                }

                break;
        }

    }
}
